{  Statement: http://acmp.ru/?main=task&id_task=457
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    n,k,t,ans:longint;
    a:array[0..10] of longint;

procedure sort(l,r:longint);

var
    i,j,x,y:longint;

begin
i := l;
j := r;
x := a[(l + r) shr 1];
repeat
    while a[i] > x do inc(i);
    while a[j] < x do dec(j);
    if i <= j then begin
        y := a[i];
        a[i] := a[j];
        a[j] := y;
        inc(i);
        dec(j);
    end;
until i > j;
if l < j then sort(l, j);
if i < r then sort(i, r);
end;

procedure get(n:longint);
begin
a[1] := n div 1000;
a[2] := n div 100 mod 10;
a[3] := n div 10 mod 10;
a[4] := n mod 10;
end;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
ans := 0;
while true do begin
    get(n);
    sort(1,4);
    k := a[1] * 1000 + a[2] * 100 + a[3] * 10 + a[4];
    t := a[4] * 1000 + a[3] * 100 + a[2] * 10 + a[1];
    if k - t = n then break else begin
        inc(ans);
        n := k - t;
    end;
end;
writeln(n);
write(ans);
end.
